package com.imooc.animationtest;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.AnimationSet;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

//    @BindView(R.id.image)
//    ImageView image;
//    @BindView(R.id.image1)
//    ImageView image1;
//    @BindView(R.id.image2)
//    ImageView image2;
//    @BindView(R.id.image3)
//    ImageView image3;
//    @BindView(R.id.image4)
//    ImageView image4;
//    @BindView(R.id.image5)
//    ImageView image5;
//    @BindView(R.id.image6)
//    @BindViews({R.id.image,R.id.image1,R.id.image2,R.id.image3,R.id.image4,R.id.image5,R.id.image6})
//    List<ImageView> images;
//    ImageView[] images;
//    @BindArray(R.array.items)
//    String[] array;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

    }

    public void click(View view){
        final Button button= (Button) view;
        ValueAnimator valueAnimator=ValueAnimator.ofInt(0,100);
        valueAnimator.setDuration(5000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                Integer value= (Integer) valueAnimator.getAnimatedValue();
                button.setText(""+value);
            }
        });
        valueAnimator.start();
    }
//    private boolean flag=true;
//    public void onClick(View view){
//        switch (view.getId()){
//            case R.id.image:
//                if(flag){
//                    startAnimation();
//                    flag=false;
//                }else{
//                    stopAnimation();
//                    flag=true;
//                }
//                break;
//            default:
//                Toast.makeText(MainActivity.this,"id"+view.getId()+"is clicked",Toast.LENGTH_SHORT).show();
//                break;
//        }
//    }
//
//    private void startAnimation(){
//        for(int i=6;i>=0;i--){
//            ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(images.get(i),"translationY",0,i*150);
//            objectAnimator.setDuration(100);
//            objectAnimator.setStartDelay(i*100);
//            objectAnimator.setInterpolator(new OvershootInterpolator());
//            objectAnimator.start();
//        }
//    }
//
//    private void stopAnimation(){
//
//        for(int i=6;i>=0;i--){
//            ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(images.get(i),"translationY",i*150,0);
//            objectAnimator.setDuration(100);
//            objectAnimator.setStartDelay(i*100);
//            objectAnimator.setInterpolator(new AnticipateInterpolator());
//            objectAnimator.start();
//        }
//    }
//
//    public void click(View view){
//        Toast.makeText(this,"clicked",Toast.LENGTH_SHORT).show();
//        ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(view,"alpha",0f,1F);
//        objectAnimator.setDuration(1000);
//        objectAnimator.addListener(new AnimatorListenerAdapter() {
//            @Override
//            public void onAnimationEnd(Animator animation) {
//                Toast.makeText(MainActivity.this,"animation played",Toast.LENGTH_SHORT).show();
//                super.onAnimationEnd(animation);
//            }
//        });
//        objectAnimator.addListener(new Animator.AnimatorListener() {
//            @Override
//            public void onAnimationStart(Animator animator) {
//
//            }
//
//            @Override
//            public void onAnimationEnd(Animator animator) {
//                Toast.makeText(MainActivity.this,"animation played",Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onAnimationCancel(Animator animator) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animator animator) {
//
//            }
//        });
//    }
//    ----------------------------------------------------------------------------------
//    public void move(View view){
//        TranslateAnimation translateAnimation=new TranslateAnimation(0,200,0,0);
//        translateAnimation.setDuration(500);
//        imageView.startAnimation(translateAnimation);
//        translateAnimation.setFillAfter(true);
//        ObjectAnimator.ofFloat(imageView,"alpha",0f,100f).setDuration(500).start();
//        ObjectAnimator.ofFloat(imageView,"rotation",0f,360f).setDuration(500).start();
//        ObjectAnimator.ofFloat(imageView,"translationX",0f,100f).setDuration(500).start();
//        PropertyValuesHolder propertyValuesHolder_alpha=PropertyValuesHolder.ofFloat("alpha",0f,100f);
//        PropertyValuesHolder propertyValuesHolder_rotation=PropertyValuesHolder.ofFloat("rotation",0f,360f);
//        PropertyValuesHolder propertyValuesHolder_translation=PropertyValuesHolder.ofFloat("translationX",0f,300f);
//        ObjectAnimator.ofPropertyValuesHolder(imageView,
//                propertyValuesHolder_alpha,
//                propertyValuesHolder_translation,
//                propertyValuesHolder_rotation).setDuration(500).start();
//        ObjectAnimator oa_alpha=ObjectAnimator.ofFloat(imageView,"alpha",0f,100f);
//        ObjectAnimator oa_rotation=ObjectAnimator.ofFloat(imageView,"rotation",0f,360f);
//        ObjectAnimator oa_translation=ObjectAnimator.ofFloat(imageView,"translationX",0f,100f);
//        AnimatorSet animatorSet=new AnimatorSet();
//        animatorSet.playTogether(oa_alpha,oa_rotation,oa_translation);
//        animatorSet.setDuration(500);
//        animatorSet.start();

//    }
}
